<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Document</title>
    <link rel="stylesheet" href="../../css/api.css">
    <link rel="stylesheet" href="../../css/news.css?v=1.0.1">
    <style>
        html,
        body {
            background: #efefef;
        }

        header {
            /* background: #673AB7; */
            color: #222A2D;
        }

        .title {
            font-size: 18px;
        }

        .more.hide {
            visibility: hidden;
        }

        .content textarea {
            width: 100%;
            resize: none;
            height: 100px;
            line-height: 20px;
            font-size: 14px;
        }

        .new-submit {
            background: #673AB7;
            line-height: 50px;
            width: 50%;
            margin: 50px 25% 20px;
        }

        .money-icon {
            width: 18px;
            height: 18px;
            display: inline-block;
            background-size: 100% 100%;
            margin-top: 5px;
            background-repeat: no-repeat;
            background-image: url('../../image/icon/money2.png');
        }

        #js-money {
            display: flex;
            justify-content: center;
        }
    </style>
</head>

<body>
    <header>
        <div class="head new-padding-10 flex-bt">
            <div class="back" tapmode onclick="_closeToWin()">取消</div>
            <div class="title">发红包</div>
            <div class="more hide">占位</div>
        </div>
    </header>
    <div class="wrap" id="view">
        <div class="flex-bt w-bg new-margin-10 new-padding-10" style="border-radius: 5px;">
            <span>金额</span>
            <div class="input">
                <input type="number" style="text-align: right;" placeholder="0.00" onkeyup="limitMoney(this)">
                <span>USDT</span>
            </div>
        </div>
        <div class="content w-bg new-margin-10 new-padding-10" style="border-radius: 5px;">
            <textarea name="" id="js-content" placeholder="小小意思，以表心意"></textarea>
        </div>
        <h1 style="text-align: center;" id="js-money">
            <i class="money-icon"></i>
            <span>0.00</span>
        </h1>
        <button class="new-submit" onclick="selectType()">塞钱进红包</button>
    </div>
</body>
<script src="../../script/jquery_min.js"></script>
<script src="../../script/ffkj.js?v=1.0.1"></script>
<script src="../../script/vue.js"></script>
<script>
    var view = new Vue({
        el: '#view',
        data: {
            ffList: [],
            ffInfo: {},
        },
        methods: {
            _url: function (param, url) {
                _url(param, url);
            },
        }
    })
    var pageParam = getParam();
    var touserid = pageParam['touserid'];
    // 格式化输入
    function limitMoney(obj) {
        obj.value = obj.value.replace(/[^0-9.]*$/, ""); //清除"数字"和"."以外的字符
        obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
        obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
        var money = obj.value || '0.00';
        $('#js-money span').text(money);
    }
    // 选择支付方式
    function selectType() {
        var money = $.trim($('.input input').val());
        if (!money || Number(money) <= 0) {
            _msg('请输入金额');
            return;
        }
        // var buttons = ['余额', '支付宝', '微信']; // 1,2,3
        // var buttons = ['余额', '微信'];
        // var peyIndex = [1, 3];
        // _action('选择支付方式', buttons, function (bIndex) {
        //     if (bIndex != buttons.length + 1) {
        submit(1, money);
        //     }
        // })
    }

    // 发红包
    function submit(index, money) {
        var content = $.trim($('#js-content').val());
        if (!content) {
            content = '小小意思，以表心意';
        }
        _log(index)
        _loading();
        _ajax('home/Privatechat/addTalk', function (ret, err) {
            pushMsg(touserid);
            _log(JSON.stringify(ret));
            _log(JSON.stringify(err));
            // if (ret && ret.code == 200) {
                _closeToWin()
            // } else {
            //     _msg(ret.msg);
            // }
        }, {
            money: money,
            ways: index,
            content: content,
            type: 5,
            userid: myuserid,
            touserid: touserid,
        })
    }
</script>

</html>